#pragma once
#include "loki/Singleton.h"
#include "threadsafemap.h"
#include "SSMessageDef.h"
#include "sharedqueue.h"
#include "StrategyRunner.h"
#include "threadtask.h"

#pragma warning(disable : 4482)
class CStrategyRunnerMgr : public LIB_NS:: ThreadTask
{
public:
	CStrategyRunnerMgr(void);
	virtual ~CStrategyRunnerMgr(void);

	virtual int svc()
	{
		bool ret = ProcessMsg();
		return 0;
	}

	bool Run()
	{
		this->activate();	
		return true;
	}

	bool EnqueueMsg(SSMessageBase msg)
	{
		//if(msg.ID == SSMessageID::SysStart)
		m_msgqueue.enqueue(msg);
		return true;			 
	}
protected:
	virtual bool ProcessMsg()
	{

		while(true)
		{

			SSMessageBase msg = m_msgqueue.dequeue();
			switch( msg.ID )
			{
			case SSMessageID::SysStop :
				{
					ProcessSysStop();
					break;
				}
				
			case SSMessageID::StrategyDel:
				{
					break;
				}
			case SSMessageID::StrategyAdd:
				{
					break;
				}
			case  SSMessageID::StrategyMod:
				{
					break;
				}
			case  SSMessageID::StrategyStart:
				{
					break;
				}

				
			case SSMessageID::SysStart:
				{
					ProcessSysStart();
					break;
				}
			default:
				break;
			}

		}
		return true;

	}
	bool ProcessSysStop();
	bool ProcessSysStart();
	bool ProcessStrategyDel();
protected:
	typedef theadmap<CStrategyRunner::TokenType, CStrategyRunnerPtr> StrategyMaps;
	
	StrategyMaps m_strategys;
	blockabledqueue<SSMessageBase> m_msgqueue;
	


};
	

typedef Loki::SingletonHolder<CStrategyRunnerMgr> CStrategyRunnerMgrHolder;